package nk.greedy;

import java.util.Arrays;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.Scanner;

public class AB31 {


    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        int n = in.nextInt();
        int[][] time = new int[n][2];

        for (int i = 0; i < n; i++) {
            time[i][0]= in.nextInt();
            time[i][1] = in.nextInt();

        }
        Arrays.sort(time, new Comparator<int[]>() {
            @Override
            public int compare(int[] o1, int[] o2) {
                return o1[0] == o2[0] ? o1[1] - o2[1] : o1[0] - o2[0];
            }
        });
        LinkedList<int[]> stack = new LinkedList<>();
        stack.push(time[0]);

        for (int i = 1; i < time.length; i++) {
            if (time[i][0] < stack.peek()[1]) {
                if (stack.peek()[1] >= time[i][1]) {
                    stack.pop();
                    stack.push(time[i]);
                } // 否则当前time[i]丢掉
            } else {
                stack.push(time[i]);
            }
        }
        System.out.println(stack.size());
    }









}
